<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>修改库存记录</title>
    <link rel="stylesheet" href="../frame/layui/css/layui.css">
    <link rel="stylesheet" href="../frame/static/css/style.css">
</head>
<body class="body">

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>修改库存记录</legend>
</fieldset>

<form class="layui-form" >

    <div class="layui-form-item">
        <label class="layui-form-label">库存编号</label>
        <div class="layui-input-inline">
            <input type="text" name="repId" id="repId" lay-verify="required|number" hidden="hidden" placeholder="请输入配件名称" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">配件名称</label>
        <div class="layui-input-inline">
            <input type="text" name="repName" id="repName" lay-verify="required" placeholder="请输入配件名称" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">必填</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">品牌</label>
        <div class="layui-input-inline">
            <input type="text" name="repDrand" id="repDrand" lay-verify="required" placeholder="请输入品牌" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">必填</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">进价</label>
        <div class="layui-input-inline">
            <input type="text" name="repOriginal" id="repOriginal" lay-verify="required|number" placeholder="请输入进价" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">必填(数字)</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">展示图片</label>
        <div class="layui-input-inline">
            <input type="text" name="repImage" id="repImage" lay-verify="required|url" placeholder="请输入图片url" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">必填</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">适用车型</label>
        <div class="layui-input-block">
            <input type="text" name="repVehicle" id="repVehicle" autocomplete="off" placeholder="请输入适用车型(可选)" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">配件型号</label>
        <div class="layui-input-inline">
            <input type="text" name="repModel" id="repModel" lay-verify="required" placeholder="请输入配件型号" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">必填</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">售价</label>
        <div class="layui-input-inline">
            <input type="text" name="repMoney" id="repMoney" lay-verify="required|number" placeholder="请输入售价" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">必填(数字)</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">库存数量</label>
        <div class="layui-input-inline">
            <input type="text" name="repNum" id="repNum" lay-verify="required|number" placeholder="请输入初始数量" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">必填(数字)</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">简介</label>
        <div class="layui-input-block">
            <textarea name="repBrief" id="repBrief" placeholder="请输入内容(可选)" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">修改</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="../js/jquery.js"></script>
<script src="../frame/layui/layui.js" charset="utf-8"></script>
<script src="../js/dateToString.js"></script>
<script>
    $(function () {

        // 获取编号
        var repId=window.location.search.slice(window.location.search.lastIndexOf("?")+1);
        $("#repId").val(repId);
        // 加载数据
        $.ajax({
            url: "/stock/queryStockByRepId",
            type: "POST",
            dataType:"json",
            async:false,
            data: {repid:repId},
            success: function(data){
                console.log(data);
                $("#repId").val(data.data.repid);
                $("#repName").val(data.data.repname);
                $("#repDrand").val(data.data.repdrand);
                $("#repOriginal").val(data.data.reporiginal);
                $("#repImage").val(data.data.repimage);
                $("#repVehicle").val(data.data.repvehicle);
                $("#repModel").val(data.data.repmodel);
                $("#repMoney").val(data.data.repmoney);
                $("#repNum").val(data.data.repnum);
                $("#repBrief").val(data.data.repbrief);
            }
        });
    });

    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,laydate = layui.laydate;

        // 表单提交验证
        form.on('submit(demo1)', function(data){
            update(data);
            return false;
        });

    });
    // 修改数据
    function update(data){
        var repId = data.field.repId;

        var repName = data.field.repName;

        var repBrief = data.field.repBrief;

        var repDrand = data.field.repDrand;

        var repOriginal = data.field.repOriginal;

        var repImage = data.field.repImage;

        var repVehicle = data.field.repVehicle;

        var repModel = data.field.repModel;

        var repMoney = data.field.repMoney;

        var repNum = data.field.repNum;
        $.ajax({
            url: "/stock/updatestock",
            type: "POST",
            dataType:"json",
            data: {
                repid:repId,
                repname:repName,
                repbrief:repBrief,
                repdrand:repDrand,
                reporiginal:repOriginal,
                repimage:repImage,
                repvehicle:repVehicle,
                repmodel:repModel,
                repmoney:repMoney,
                repnum:repNum
            },
            success: function(data){
                if(data.success){
                    window.location.href="/stock/outstock/outstocklist.jsp";
                }else {
                    layer.msg(data.message);
                }
            }
        });
    }
</script>
</body>
</html>
